Software patches are, generally, independent software units which are issued in order to modify certain functions of an existing software system or correct certain faults of an existing software system. A dynamic software patch upgrading technology can complete repair for system functions or faults with no influence on normal running of the system, by which a currently running function in the existing system is replaced with a patching function generally, and therefore functions of the function are changed.
In an embedded system, although the dynamic patch upgrading technology has multiple implementation solutions, the technology mainly includes, to sum up, key steps as follows.
1, a patching function funcA is re-written and compiled in a background (a personal computer, generally), and a patch file fileB is generated;
2, the patch file fileB is downloaded into a foreground target machine;
3, an upgrading service module in the foreground target machine parses the patch file, and obtains addresses of the patching function funcA and a patched function funcC in a memory; and
4, initial instructions of the patched function funcC are modified into jump instructions, which jump to the patching function funcA.
Thus, when the function funcC is called, the initial instruction of the function funcC directly jumps to the function funcA for execution due to being a jump instruction, and then directly returns to a next instruction of the function funcC, thereby achieving the aim of replacing the function funcC with the function funcA.
If the relative address between the patching function funcA and the patched function funcC in the memory is small and within a short jump address range, dynamic patch upgrading can be realized by a short jump. However, with the gradual increase of a software scale, when sizes of a code segment and a data segment of a mapping file of a version exceed the short jump address range, and when a relative distance between the patching function and the patched function in the memory also exceeds the short jump address range, the dynamic patch upgrading cannot be realized by the short jump.
Long jump instructions in the traditional art may be completed by at least three instructions; if the initial instructions of a patched function are modified into long jump instructions, then the first three instructions of the initial instructions of the patched function are modified at least, and situations may occur as follows:
1, if a Program Counter (PC for short) pointer of a task A is just located at the second instruction or the third instruction at the start of the initial instructions of the patched function, then an unpredictable result is about to be caused when the task A is dispatched to run again; 2, if a PC pointer of a task B is located at the first instruction at the start of the initial instructions of the patched function, then the patching function can be normally executed when the task B is dispatched to run again; and 3, when a PC pointer of a task C is located at an unmodified instruction of the patched function, the patched function can be normally executed when the task C is dispatched to run again.
On the basis of the abovementioned process, it can be shown that there is no method capable of ensuring that a modified system runs normally in the traditional art after the initial instructions of the patched function are modified into long jump instructions.